//Programs TABLE7(PartI)A and TABLE7(PartI)B produce the univariate time series results in TABLE 7.
//The programs are intended to be run in tandem, with program A run first.
//It takes approximately 20 minutes on a laptop to run 10,000 iterations.

etime, start
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\HURWICZ BIAS\REVISION FOR ECONOMIC MODELLING\PROGRAMS2\TABLE7(PartI).smcl", replace
drop _all
clear
graph drop _all
set more off
set seed 13

matrix medLRP = J(4,3,0)
matrix confidLRP = J(4,6,0)
matrix meanRR = J(4,3,0)

local bigobs = 1100
local beta0 = 0
local betax = 1 
local reps = 10000

local i = 1
foreach betay in 0.60 0.90 {
foreach rhox in 0 1 {
local j = 1
   foreach smallobs in 10 50 1000 {
      simulate LRP = r(LRP) pLRP = r(pLRP), ///
         reps(`reps'): TABLE7prog, beta0(`beta0') betax(`betax') betay(`betay') ///
		 rhox(`rhox') smallobs(`smallobs') bigobs(`bigobs') 
		 
		  summ LRP, detail
		  matrix medLRP[`i', `j'] = r(p50)
		  matrix confidLRP[`i',1+(`j'-1)*2] = r(p5)
		  matrix confidLRP[`i',2+(`j'-1)*2] = r(p95)
		  generate RejectRate = 0
		  replace RejectRate = 1 if pLRP < 0.05  
		  summ RejectRate, meanonly
		  matrix meanRR[`i',`j'] = r(mean)
		local `++j'
		}
	local `++i'
	}
}

matrix colnames medLRP = "T10(P50)" "T50(P50)" "T1000(P50)" 
matrix rownames medLRP= R00B60 R100B60 R00B90 R100B90
matrix colnames confidLRP = "T10(P5)" "T10(P95)" "T50(P5)" "T50(P95)" ///
                             "T1000(P5)" "T1000(P95)"
matrix rownames confidLRP = R00B60 R100B60 R00B90 R100B90
matrix colnames meanRR = T10 T50 T1000
matrix rownames meanRR = R00B60 R100B60 R00B90 R100B90
matrix list medLRP
matrix list confidLRP
matrix list meanRR

etime

log close
